<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    body{
        display: flex;
        justify-content: center;
        align-items: center;
        margin-top: 100px;
    }
    .container{
        background-color: aquamarine;
        width: 450px;
        height: 350px;
        text-align: center;
    }
</style>
<body>
    <div class="container">
        以图形的中点作为坐标轴的0点，然后根据鼠标进入的位置，计算进入的角度来进行鼠标移入方向的判断
    </div>
</body>
<script>
    const container =document.querySelector('.container')
    const rect = container.getBoundingClientRect();
    const theta = Math.atan2(rect.height,rect.width);
    container.addEventListener('mouseenter',(e)=>{
        const x = e.offsetX -rect.width/2;
        const y = rect.height/2 -e.offsetY;
        const d = Math.atan2(y,x);
        if(d<theta&&d>=-theta){
            console.log('右')
        }else if(d>=theta&&d<Math.PI-theta){
            console.log('上')
        }else if(d>=Math.PI-theta||d<-(Math.PI-theta)){
            console.log('左')
        }else{
            console.log('下')
        }
    })
</script>
</html>